using Boo.Lang.Runtime;
using System;
using UnityEngine;

[Serializable]
public class FractalTexture : MonoBehaviour
{
	public bool gray;

	public int width;

	public int height;

	public float lacunarity;

	public float h;

	public float octaves;

	public float offset;

	public float scale;

	public float offsetPos;

	private Texture2D texture;

	private Perlin perlin;

	private FractalNoise fractal;

	public FractalTexture()
	{
		gray = true;
		width = 128;
		height = 128;
		lacunarity = 6.18f;
		h = 0.69f;
		octaves = 8.379f;
		offset = 0.75f;
		scale = 0.09f;
	}

	public void Start()
	{
		texture = new Texture2D(width, height, TextureFormat.RGB24, mipChain: false);
		GetComponent<Renderer>().material.mainTexture = texture;
	}

	public void Update()
	{
		Calculate();
	}

	public void Calculate()
	{
		if (RuntimeServices.EqualityOperator(perlin, null))
		{
			perlin = new Perlin();
		}
		fractal = new FractalNoise(h, lacunarity, octaves, perlin);
		for (int i = 0; i < height; i++)
		{
			for (int j = 0; j < width; j++)
			{
				if (gray)
				{
					float num = fractal.HybridMultifractal((float)j * scale + Time.time, (float)i * scale + Time.time, offset);
					texture.SetPixel(j, i, new Color(num, num, num, num));
					continue;
				}
				offsetPos = Time.time;
				float r = fractal.HybridMultifractal((float)j * scale + offsetPos * 0.6f, (float)i * scale + offsetPos * 0.6f, offset);
				float g = fractal.HybridMultifractal((float)j * scale + 161.7f + offsetPos * 0.2f, (float)i * scale + 161.7f + offsetPos * 0.3f, offset);
				float b = fractal.HybridMultifractal((float)j * scale + 591.1f + offsetPos, (float)i * scale + 591.1f + offsetPos * 0.1f, offset);
				texture.SetPixel(j, i, new Color(r, g, b, 1f));
			}
		}
		texture.Apply();
	}

	public void Main()
	{
	}
}
